<?php


namespace app\api\lists;


use app\common\enum\DefaultEnum;
use app\common\model\staff\Staff;

class StaffLists extends BaseShopDataLists
{
    /**
     * @notes 搜索条件
     * @return \string[][]
     * @author ljj
     * @date 2022/2/23 5:48 下午
     */
    public function where(): array
    {
        $where[] = ['status','=',DefaultEnum::SHOW];
        if (isset($this->params['name']) && $this->params['name'] != '') {
            $where[] = ['name','like','%'.$this->params['name'].'%'];
        }

        return $where;
    }

    /**
     * @notes 师傅列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author ljj
     * @date 2022/2/23 5:56 下午
     */
    public function lists(): array
    {
        $lists = Staff::field('id,user_id,name,goods_ids,province_id,city_id,district_id,address')
            ->where($this->where())
            ->append(['goods_name','user_image','province','city','district'])
            ->order(['id'=>'desc'])
            ->select()
            ->toArray();

        return $lists;
    }

    /**
     * @notes 师傅总数
     * @return int
     * @author ljj
     * @date 2022/2/23 5:56 下午
     */
    public function count(): int
    {
        return Staff::where($this->where())->count();
    }
}